<?php
	include_once('./server/fileUpload.php');
	function getSenderName($orderID)
	{
		$sense = explode('zdghd', $orderID);
		
		$tables = array();
		$tables[0] = 'ex_pending_orders';
		
		$fields = array();
		$fields[0] = 'memberID';
		
		$whereClause = 'orderID="'.$sense[1].'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		$memberID = $data['memberID'][0];
		
		$tables = array();
		$tables[0] = 'ex_shoppers';
		
		$fields = array();
		$fields[0] = 'name';
		
		$whereClause = 'memberID = "'.$memberID.'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
		$splitName = explode(', ', $data['name'][0]);
		
		return $splitName[1];
	}
	function getOrderDetails($orderID, $hash)
	{
		$tables = array();
		$tables[0] = 'ex_pending_orders';
		
		$fields = array();
		$fields[0] = 'orderDetails';
		$fields[1] = 'expiry';
		$fields[2] = 'imgFile';
		
		$whereClause = 'hash="'.$hash.'" AND orderID="'.$orderID.'" AND expiry > "'.sqlDateNow().'"';
		
		$data = SQLRecover($tables, $fields, $whereClause);
		
/* 		echo $data['traceSQL']; */
		if($data['queryStatus'] == 'DB Query success!')
		{
			if($data['imgFile'][0] == 'noImg.jpg')
			{
				$return = array();
				$return['details'] = $data['orderDetails'][0];
				$return['expires'] = $data['expiry'][0];
				$return['img'] = $data['imgFile'][0];
				return $return;
			}
			else
			{
				$return = array();
				$return['details'] = $data['orderDetails'][0];
				$return['expires'] = $data['expiry'][0];
				$return['img'] = $data['imgFile'][0];
				return $return;
			}
		}
		else
		{
			$return['details'] = 'Error 404: File Not Found.';
			$return['expires'] = 'N/A';
			$return['img'] = 'N/A';
			return $return;

		}
		
	}

	function displayPage()
	{	
		if(get('orderID') != 'null')
		{
			if(isset($_POST['airyywh']))
			{
				$fileHash = rand(10000, 99999);
				
				$fileStuff = frmFile('fileUpload');
				
				$fileDtails = explode('.', $fileStuff['name']);
				
				receiveFile('fileUpload', $fileHash, $fileDtails[1], './img/a1ow17n1y437bawg42147/', $_POST['airyywh']);
				
				$orderDetails = explode('zdghd', get('orderID'));
				
				$tableName = 'ex_pending_orders';
				
				$fields = array();
				$fields[0] = 'imgFile';
				
				$values = array();
				$values[0] = $fileHash.'.'.$fileDtails[1];
				
				$whereClause = 'orderID = "'.$orderDetails[1].'"';
				
				$data = SQLUpdate($tableName, $whereClause, $fields, $values);
			}
			$values = explode('zdghd', get('orderID'));
			if(isset($values[1]))
			{
				$val = getOrderDetails($values[1], $values[0]);
				if($val['img'] != 'N/A')
				{
					$uploadText= ($val['img'] != 'noImg.jpg' ? '<p>Hi '.getSenderName(get('orderID')).',<br />This order has been confirmed and your deposit slip has been submitted. If you wish to change your order or re-upload another deposit slip, please inform us through <a href="mailto:inquiry@soleservice.com.ph">inquiry@soleservice.com.ph</a></p>' : '<p>Hi '.getSenderName(get('orderID')).',<br />This order is still pending and will expire on '.dateParser(explode('-', $val['expires'])).'. To confirm your order, upload/re-upload a scanned copy or a photograph of your deposit slip below. Details must be readable.</p>');
					
					//FILE NAME
					//WAYBILL
					//PAID
					if(!file_exists(CM_ROOTDIR.'img/a1ow17n1y437bawg42147/'.$val['img']) && $val['img'] != 'paid')
					{
						if($val['img'] == '0')
						{
							$waybill = '
							<div class="grid_12 waybillContain">
								<h3>Ready For Pickup</h3>
							</div>
							<div class="grid_12 pick endingNote">
								Your order is currently ready for pickup at #7 Makaturing St. cor. Banawe, Quezon City. Click <a href="'.INDEX.'shipping" target="_blank">here</a> for a location map. We hope you enjoyed shopping in Sole Service Manila. For any questions or suggestions, please feel free to <a href="'.INDEX.'contact" target="_blank"><b>contact us</b></a>.
							</div>
							';
						}
						else
						{
							$waybill = '
							<div class="grid_12 centerAlign waybillContain">
								<b>Waybill Number:</b><br />
								<div class="waybill">
									'.$val['img'].'
								</div>
							</div>
							<div class="grid_5 rightAlign xendStuff">
								<a href="http://www.xend.com.ph" target="_blank"><img src="img/shipping/xend.jpg" /></a>
							</div>
							<div class="grid_4">
								To track your order, Click the Xend Logo and key in your Waybill Number above to locate your order.
							</div>
							<div class="grid_2">
								&nbsp;
							</div>
							<div class="clear">
							<!--spanner-->
							</div>
							
							<div class="grid_1">
								&nbsp;
							</div>
							<div class="grid_10 centerAlign endingNote">
								We hope you enjoyed shopping in Sole Service Manila. For any questions or suggestions, please feel free to <a href="'.INDEX.'contact"><b>contact us</b></a>.
							</div>
							<div class="grid_1">
								&nbsp;
							</div>
							';
						}
					}
					else
					{
						$waybill = '';
					}
					
					if(file_exists(CM_ROOTDIR.'img/a1ow17n1y437bawg42147/'.$val['img']))
					{
						$pStatus = 'Processing';
						$dStatus = 'Pending';
					}
					else
					{
						$pStatus = 'Confirmed';
						if($val['img'] == 'paid')
						{
							$dStatus = 'Ready for Delivery';
						}
						else
						{
							$dStatus = 'Shipping in Progress';
							if($val['img'] == '0')
							{
								$dStatus = 'Ready for Pickup';
							}
						}
					}
					
					$uploadForm = ($val['img'] != 'noImg.jpg' ? '
						<div class="clear">
						<!--spanner-->
						</div>
						
						<div class="grid_1">
						&nbsp;
						</div>
						<div class="grid_5 statuses">
						Payment Status:<br />
						<span class="pula">'.$pStatus.'</span><br /><br />
						</div>
						<div class="grid_6 statuses">
						Delivery Status:<br />
						<span class="pula">'.$dStatus.'</span>
						</div>
						<div class="clear">
						<!--spanner-->
						</div>
						'.$waybill.'
					' : '
					<div class="clear">
						<!--spanner-->
						</div>
						
						<div class="grid_1">
						&nbsp;
						</div>
						<div class="grid_5 statuses">
						Payment Status:<br />
						<span class="pula">Pending</span><br /><br />
						</div>
						<div class="grid_6 statuses">
						Delivery Status:<br />
						<span class="pula">Pending</span>
						</div>
						
						<div class="clear">
						<!--spanner-->
						</div>
						
						<div class="grid_6">
						<h3>Step 2: Make the Bank Deposit</h3>
						</div>
						<div class="grid_6">
						<h3>Step 3: Upload a copy of the Deposit Slip</h3>
						</div>
						
						<div class="clear">
						<!--spanner-->
						</div>
						
						<div class="grid_2">
						<br />
						<img src="img/home/bdo.jpg" alt="bdo" width="144" height="53"/>
						</div>
						<div class="grid_4">
						<b>
						<br />
						Account Details: AREN VANCE PE<br />
						Account Number: 6220112686<br />
						Branch: Banco De Oro Del Monte Sienna
						</b>
						<br /><br /><br /><br /><br /><br /><br />
						</div>
						<div class="grid_6">
							<form enctype="multipart/form-data" method="POST" action="'.INDEX.'orderSent'.EXT.'orderID='.get('orderID').'">
								<input type="hidden" name="airyywh" value="oieughejsnce310" />
								<input type="file" name="fileUpload" class="fileUp" />
								<input type="submit" value="Upload Image" class="submit"/>
								<br /><br /><br /><br />
							</form>
						</div>
					');
								
					$output = '
					<div class="container_12">
						<div class="grid_12">
							<h2>Payment Confirmation</h2>
							'.$uploadText.'
							<h3>'.($val['img'] != 'noImg.jpg' ? 'Your Order Details' : 'Step1: Review Your Order').'</h3>
							<b>ORDER NUMBER: '.get('orderID').'</b>
						</div>
						<div class="clear">
						<!--spanner-->
						</div>
						
						<div class="grid_12 detailsPresent">
							
							<p>
								'.$val['details'].'
							</p>
						</div>
						'.$uploadForm.'						
					</div>
					';
				}
				else
				{
					$output = '
					<div class="container_12">
						<div class="grid_2">
							&nbsp;
						</div>
						<div class="grid_8 detailsAbsent">
							<p>
								The order you are looking for does not exist in any active accounts. The order has either been received or expired. Sorry for the inconvenience.
							</p>
						</div>
						<div class="grid_2">
							&nbsp;
						</div>
					</div>
					';
				}
			}
			else
			{
				$output = "Error 404: File Not Found.";
			}
		}
		else
		{
			$output = "Error 404: File Not Found.";
		}
		
		return $output;
	}
?>